(function(angular) {
	'use strict';
	angular.module('fs.waf').factory('fileLoadService', fileLoadService);
	fileLoadService.$inject = [ '$q', 'loggerFactory', 'commonService', 'ajaxServiceFactory'];
	function fileLoadService($q, loggerFactory, commonService, ajaxServiceFactory) {
		var log = loggerFactory.getLogger("fiService");
		
		var ajaxService = ajaxServiceFactory.buildAjaxService({
			getCountries : {
				url : 'do/cda/dataList/country',
				method : 'get'
			},
			getStates : {
				url : 'do/cda/dataList/states',
				method : 'post'
			},
			getCities : {
				url : 'do/cda/dataList/cities',
				method : 'post'
			},
			getFiCodeTypes : {
				url : 'do/cda/dataList/fiCodeTypes',
				method : 'post'
			}
		});
		
		function getCountryOptions() {
			var defer = $q.defer();
			ajaxService.getCountries().then(function(response) {
				defer.resolve(response);
			});
			return defer.promise;
		}
		function getFiCodeTypeOptions() {
			var defer = $q.defer();
			ajaxService.getFiCodeTypes().then(function(response) {
				defer.resolve(response);
			});
			return defer.promise;
		}
		
		function dateDisabled(dateModel) {
			var date = dateModel.date, mode = dateModel.mode;
			return mode === 'day' && commonService.isHoliday(date);
		}
		
		function initGeneral($scope, ctrl){
			ctrl.countryOptions = {};
			ctrl.countryOptions.hasEmptyOption = true,
			ctrl.stateOptions = {};
			ctrl.stateOptions.hasEmptyOption = true,
			ctrl.cityOptions = {};
			ctrl.cityOptions.hasEmptyOption = true,
			ctrl.fiCodeTypeOptions ={};
			
			getCountryOptions().then(function(response) {
				angular.extend(ctrl.countryOptions, response);
			});
			
			getFiCodeTypeOptions().then(function(response) {
				angular.extend(ctrl.fiCodeTypeOptions, response);
			});
			
		}
		
		return {
			dateDisabled : dateDisabled,
			initGeneral : initGeneral
		};
	}
})(angular);